<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>学生管理</title>
    <link rel="stylesheet" href="/css/common2.css">
    <link rel="stylesheet" href="/css/popup.css">
    <link rel="stylesheet" href="/scriptZIP/vue-select.min.css">
    <link rel="stylesheet" href="/scriptZIP/index.css">
    <script src="/scriptZIP/qrcode.min.js"></script>
    <style>
        [v-cloak] {
            display: none;
        }

        html {
            height: auto;
            overflow-y: scroll;
        }

        /* body {
            background-color: #E8E9EA;
        }*/
        .custom-input .el-input__inner {
            height: 34px !important;
        }

        .qr-border .q-img {
            width: 200px;
            height: 200px;
            margin: 0 auto;
        }
    </style>
</head>

<body>
    <div id="vue-root" v-cloak style="margin-top: 30px; margin: 0 auto; margin-bottom: 50px; ">
        <div>
            <el-descriptions title="学员信息" border>
                <el-descriptions-item label="学员姓名">{{dataForm.name}}</el-descriptions-item>
                <el-descriptions-item label="手机号">{{dataForm.bindCode}}</el-descriptions-item>
                <!-- <el-descriptions-item label="居住地">{{dataForm.address}}</el-descriptions-item> -->
                <!-- <el-descriptions-item label="学生来源">{{dataForm.casea}} </el-descriptions-item> -->
                <!-- <el-descriptions-item label="联系地址">{{dataForm.address}}</el-descriptions-item> -->
                <el-descriptions-item label="就读学校">{{dataForm.schoolName}}</el-descriptions-item>
                <!-- <el-descriptions-item label="年龄">{{dataForm.schoolName}}</el-descriptions-item> -->
            </el-descriptions>
        </div>
        <div>
            <el-button style="margin-top: 20px; margin-left: 40px;" @click="visibleopen" plain>选择课程</el-button>

            <!-- 课程弹窗 -->
            <el-dialog title="选择课程" :visible.sync="dialogTableVisible">
                <el-form :inline="true" :model="form" @keyup.enter.native="searchDataList()">
                    <el-form-item label="课程名称">
                        <el-input class="custom-input" v-model="input" placeholder="请输入内容"></el-input>
                    </el-form-item>
                    <el-form-item>
                        <el-button size="small" type="primary" @click="searchDataList()">查询</el-button>
                    </el-form-item>
                </el-form>
                <el-alert title="双击确定所选择的数据" show-icon type="info">
                </el-alert>
                <el-table ref="singleTable" :data="gridData" highlight-current-row @current-change="handleCurrentChange"
                    @row-dblclick="handleRowDoubleClick">
                    <el-table-column property="name" label="课程名称" width="150"></el-table-column>
                    <el-table-column property="name" label="类型" width="200">
                        <template slot-scope="scope">
                            <div>
                                <span v-if="scope.row.type==1">一对一</span>
                                <span v-else>一对多</span>
                            </div>
                        </template>
                    </el-table-column>
                    <el-table-column property="address" label="收费方式">
                        <template slot-scope="scope">
                            <div>
                                <span v-if="scope.row.month && scope.row.month.length > 0">按月</span>
                                <span v-if="scope.row.dailyRate && scope.row.dailyRate.length > 0">按天</span>
                                <span v-if="scope.row.classHour && scope.row.classHour.length > 0">按课时</span>
                                <span
                                    v-if="scope.row.quarterlyHarvest && scope.row.quarterlyHarvest.length > 0">按季</span>
                                <span v-if="scope.row.forwardHarvest && scope.row.forwardHarvest.length > 0">按期</span>
                                <span v-if="scope.row.lessonPackage && scope.row.lessonPackage.length > 0">按课包</span>
                                <span v-if="scope.row.experience && scope.row.experience.length > 0">按体验</span>
                            </div>
                        </template>
                    </el-table-column>

                    <el-table-column property="address" label="收费标准">
                        <template slot-scope="scope">
                            <div>
                                <p v-for="item in scope.row.month">
                                    <span>{{item.name}} {{item.price}}元/月</span>
                                </p>
                                <p v-for="item in scope.row.dailyRate">
                                    <span>{{item.name}} {{item.price}}元/天</span>
                                </p>
                                <p v-for="item in scope.row.classHour">
                                    <span>{{item.name}} {{item.price}}元/课时</span>
                                </p>
                                <p v-for="item in scope.row.quarterlyHarvest">
                                    <span>{{item.name}} {{item.price}}元/季</span>
                                </p>
                                <p v-for="item in scope.row.forwardHarvest">
                                    <span>{{item.name}} {{item.price}}元/期</span>
                                </p>
                                <p v-for="item in scope.row.lessonPackage">
                                    <span>{{item.name}} {{item.price}}元/课包</span>
                                </p>
                                <p v-for="item in scope.row.experience">
                                    <span>{{item.name}} {{item.price}}元/体验</span>
                                </p>
                            </div>
                        </template>
                    </el-table-column>
                </el-table>
                <el-pagination style="margin-top: 20px;" @size-change="sizeChangeHandle"
                    @current-change="currentChangeHandle" :current-page="pageIndex" :page-sizes="[5, 10, 20, 50]"
                    :page-size="pageSize" :total="totalPage" layout="total, sizes, prev, pager, next, jumper">
                </el-pagination>
            </el-dialog>

            <el-table style="width: 95%; margin: 0 auto; margin-top: 20px;" height="350" fit ref="singleTable"
                :data="selectedCourses" highlight-current-row style="width: 100%" highlight-current-row
                default-expand-all>
                <el-table-column property="name" type="expand" align="center">
                    <template slot-scope="scope">
                        <div>
                            开课日期: <el-date-picker v-model="scope.row.start_time" value-format="yyyy-MM-dd" type="date"
                                placeholder="选择日期" :clearable="false">
                            </el-date-picker>
                            <el-tooltip class="item" effect="dark" content="提示文字" placement="top-start">
                                <i class="el-icon-question"></i>
                            </el-tooltip>
                            &nbsp; 课程有效期至: <el-date-picker v-model="scope.row.end_time" value-format="yyyy-MM-dd"
                                type="date" placeholder="选择日期" :clearable="false">
                            </el-date-picker>
                            <el-tooltip class="item" effect="dark" content="提示文字" placement="top-start">
                                <i class="el-icon-question"></i>
                            </el-tooltip>
                            &nbsp;选择班级：<el-select v-model="scope.row.classesId" placeholder="请选择">
                                <el-option v-for="item in scope.row.classList" :key="item.id" :label="item.name"
                                    :value="item.id">
                                </el-option>
                            </el-select>
                        </div>
                    </template>
                </el-table-column>
                <el-table-column property="name" label="购买项目" align="center">
                </el-table-column>
                <el-table-column label="选择课程">
                    <template slot-scope="scope">
                        <el-select v-model="scope.row.selectedRate" placeholder="请选择"
                            @change="updateQuantity(scope.row, $event)">
                            <el-option v-for="item in scope.row.select" :key="item.id" :label="courseName(item)"
                                :value="item.id">
                            </el-option>
                        </el-select>
                    </template>
                </el-table-column>
                <el-table-column label="购买数量" align="center">
                    <template slot-scope="scope">
                        <el-input style="width: 80px;" min="1" v-model="scope.row.number" type="number">
                        </el-input>
                    </template>
                </el-table-column>
                <el-table-column property="address" label="总价" align="center">
                    <template slot-scope="scope">
                        <div>{{numberToFixed(scope.row.price,scope.row.number)}}</div>
                    </template>
                </el-table-column>
                <el-table-column property="address" label="小计" align="center">
                    <template slot-scope="scope">
                        <!-- <div>{{scope.row.price * scope.row.number}}</div> -->
                        <el-input style="width: 80px;" min="1" v-model="scope.row.number2" type="number"
                            :placeholder="scope.row.price * scope.row.number">
                        </el-input>
                    </template>
                </el-table-column>
                <el-table-column property="address" label="操作" align="center">
                    <template slot-scope="scope">
                        <el-button type="text" @click="confirmDelete(scope.$index)">删除</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div style="text-align: right; margin-right: 150px; margin-top: 20px;">
                应收金额: <span style="font-weight: 500; font-size: 20px; color:#FB9289;">¥{{ totalAmount }}</span>
            </div>
            <div style="margin-top: 20px;">
                <span style="margin-left: 50px;"> 其他信息 </span>
                <hr style="margin-top: 5px; width: 95%; background-color: #EBEEF5; border: none; height: 1px;">
                <el-form :label-position="labelPosition" style="width: 400px; margin-top: 20px; margin-left: 50px;"
                    label-width="100px" :model="formLabelAlign">
                    <el-form-item label="类型">
                        <el-select v-model="formLabelAlign.orderType" placeholder="请选择类型">
                            <el-option label="新签" value="1"></el-option>
                            <el-option label="续费" value="2"></el-option>
                            <el-option label="新签尾款" value="3"></el-option>

                        </el-select>
                    </el-form-item>
                    <el-form-item label="收款日期">
                        <el-date-picker v-model="formLabelAlign.start_time" type="date" value-format="yyyy-MM-dd"
                            placeholder="选择日期">
                    </el-form-item>

                    <el-form-item label="业绩归属人:">
                        <el-select filterable v-model="formLabelAlign.performance" clearable placeholder="请选择业绩归属人"
                            style="width:220px">
                            <el-option v-for="(item, i) in staffUsers" :key="i" :label="item.name"
                                :value="item.id"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="备注信息">
                        <el-input style="width: 220px;" type="textarea" :rows="4" placeholder="请输入内容"
                            v-model="formLabelAlign.remark">
                        </el-input>
                    </el-form-item>
                </el-form>
                <div style="text-align: right; margin-right: 150px; margin-top: 20px;">
                    共选择了{{selectedCourses.length}}个项目
                    <el-button size="small" type="primary" @click="submit()">线上报名</el-button>
                    <el-button size="small" type="primary" @click="submit1()">线下报名</el-button>
                </div>
            </div>
            <el-dialog title="报名支付" :visible.sync="dialogVisible" width="70%" :before-close="handleClose">
                <!-- <el-descriptions title="" direction="vertical" :column="8" border>
                    <el-descriptions-item label="名称">kooriookami</el-descriptions-item>
                    <el-descriptions-item label="收费标准">18100000000</el-descriptions-item>
                    <el-descriptions-item label="购买数量">18100000000</el-descriptions-item>
                    <el-descriptions-item label="总价">18100000000</el-descriptions-item>
                    <el-descriptions-item label="小计">18100000000</el-descriptions-item>
                </el-descriptions> -->
                <el-table style="width: 95%; margin: 0 auto; margin-top: 20px;" max-height="350"
                    :data="selectedCourses">
                    <el-table-column property="address" label="名称" align="center">
                        <template slot-scope="scope">
                            <div>{{scope.row.name}}</div>
                        </template>
                    </el-table-column>
                    <el-table-column property="address" label="收费标准" align="center">
                        <template slot-scope="scope">
                            <div>{{ `${scope.row.name} - ${scope.row.price}元`}}</div>
                        </template>
                    </el-table-column>
                    <el-table-column label="购买数量" align="center">
                        <template slot-scope="scope">
                            <div>{{scope.row.number}}</div>
                        </template>
                    </el-table-column>
                    <el-table-column property="address" label="总价" align="center">
                        <template slot-scope="scope">
                            <div> {{numberToFixed(scope.row.price,scope.row.number)}}</div>
                        </template>
                    </el-table-column>
                    <el-table-column property="address" label="小计" align="center">
                        <template slot-scope="scope">
                            <div>{{scope.row.number2}}</div>
                        </template>
                    </el-table-column>
                </el-table>
                <el-descriptions style="margin-top: 20px;" title="" :column="2" :size="size">
                    <el-descriptions-item label="收款日期">{{formLabelAlign.start_time}}</el-descriptions-item>
                    <!-- <el-descriptions-item label="类型">{{formLabelAlign.orderType}}</el-descriptions-item> -->
                    <el-descriptions-item label="业绩归属人">{{filName(formLabelAlign.performance)}}</el-descriptions-item>
                    <el-descriptions-item label="备注信息">{{formLabelAlign.remark}}</el-descriptions-item>
                </el-descriptions>
                <div class="qr-border">
                    <div class="q-img" id="qrcode" ref="qrcode">
                    </div>
                </div>
                <span slot="footer" class="dialog-footer">
                    <el-button @click="dialogVisible = false">取 消</el-button>
                    <el-button type="primary" @click="dialogVisible = false">确 定</el-button>
                </span>
            </el-dialog>
        </div>

    </div>


</body>
<script src="/scriptZIP/qs.min.js"></script>
<script src="/scriptZIP/axios.min.js"></script>

<script src="/scriptZIP/vue-select.min.js"></script>

<script src="/lib/laydate/laydate.js"></script>
<script src="/js/common.js"></script>
<script src="/js/list.js"></script>
<script src="/js/auth_util.js"></script>
<script src="/scriptZIP/vue.min.js"></script>
<script src="/scriptZIP/elementUI@2.15.14.index.js"></script>


<script>
    var agentId = localStorage.getItem('agentId')
    var schoolId = top_params().id;
    var app = new Vue(merge({
        data: {
            studentId: '',
            ids: '',
            form: {},
            pageIndex: 1,
            pageSize: 10,
            totalPage: 0,
            dataForm: [],
            tableData: [],
            dialogTableVisible: false,
            gridData: [],
            input: '',
            currentRow: null,
            selectedCourses: [],
            staffUsers: [],
            start_time: '',
            labelPosition: 'right',
            formLabelAlign: {
                name: '',
                region: '',
                type: ''
            },
            dialogVisible: false,
            size: '',
            qrimg: '',//二维码
        },
        created: function () {
            axios.get('/pc/staffUser/all/' + agentId).then(function (res) {
                this.staffUsers = res.data;
            }.bind(this));
            var urlParams = new URLSearchParams(window.location.search);
            var id = urlParams.get('id');
            var ids = top_params().id;
            // console.log(id);
            if (!id) return;
            this.studentId = id
            this.ids = ids
            this.getDetail();
        },
        computed: {
            totalAmount() {
                var num = 0
                for (let i = 0; i < this.selectedCourses.length; i++) {

                    if (this.selectedCourses[i].number2) {
                        num = num + Number(this.selectedCourses[i].number2)
                    } else {
                        num = num + (Number(this.selectedCourses[i].price) * Number(this.selectedCourses[i].number))
                    }
                }
                num = num % 1 === 0 ? num : num.toFixed(2);
                return num;
            },
            totalAmount1() {
                let num = 0;
                for (let i = 0; i < this.selectedCourses.length; i++) {
                    num += Number(this.selectedCourses[i].price) * Number(this.selectedCourses[i].number);
                }
                return num % 1 === 0 ? num : num.toFixed(2);
            }


        },
        methods: {
            numberToFixed(num1, num2) {
                console.log(num1 + ',' + num2);
                var num = Number(num1) * Number(num2)
                num = num % 1 === 0 ? num : num.toFixed(2);
                return num;
            },
            //课程选择框名字
            courseName(item) {
                console.log(item, 'dhueyh');
                var str = item.name + '(' + item.price + '元/' + ['课时', '月', '天', '季', '期', '课包', '体验'][Number(item.type) - 1] + ')'
                return str;
            },
            calculateOneMonthLater() {
                const today = new Date();
                const oneMonthLater = new Date(today.getFullYear(), today.getMonth() + 1, today.getDate() + 1);
                return oneMonthLater.toISOString().slice(0, 10);
            },
            getCurrentDate() {
                return new Date().toISOString().slice(0, 10);
            },
            searchDataList() {
                this.pageIndex = 1;
                this.visibleopen()
            },
            getDetail() {
                axios.get('/pc/student/' + this.studentId, {
                    withCredentials: true,
                }).then(function (res) {
                    this.dataForm = res.data;
                }.bind(this));

            },
            visibleopen() {
                // console.log(this.input)
                this.dialogTableVisible = true;
                axios.get('/pc/course/list/' + agentId, {
                    params: {
                        name: this.input,
                        pageNum: this.pageIndex,
                        pageSize: this.pageSize
                    }
                }).then(function (res) {
                    this.gridData = res.data.list;
                    this.totalPage = res.data.total;
                    // console.log(res)
                }.bind(this));
            },
            handleRowDoubleClick(row) {
                if (row.month && row.month.length > 0) {
                    //type: 2为按月  3为按天  1为按课时 4为按季  5为按期 6为按课包  7为按体验

                    //1按课时收费  2月收费，3天收费,按季收费,按期收费,按课包收费,按体验收费
                    for (let i = 0; i < row.month.length; i++) {
                        row.month[i].type = 2
                    }
                }
                if (row.dailyRate && row.dailyRate.length > 0) {
                    for (let i = 0; i < row.dailyRate.length; i++) {
                        row.dailyRate[i].type = 3
                    }
                }
                if (row.classHour && row.classHour.length > 0) {
                    for (let i = 0; i < row.classHour.length; i++) {
                        row.classHour[i].type = 1
                    }
                }
                if (row.quarterlyHarvest && row.quarterlyHarvest.length > 0) {
                    for (let i = 0; i < row.quarterlyHarvest.length; i++) {
                        row.quarterlyHarvest[i].type = 4
                    }
                }
                if (row.forwardHarvest && row.forwardHarvest.length > 0) {
                    for (let i = 0; i < row.forwardHarvest.length; i++) {
                        row.forwardHarvest[i].type = 5
                    }
                }
                if (row.lessonPackage && row.lessonPackage.length > 0) {
                    for (let i = 0; i < row.lessonPackage.length; i++) {
                        row.lessonPackage[i].type = 6
                    }
                }
                if (row.experience && row.experience.length > 0) {
                    for (let i = 0; i < row.experience.length; i++) {
                        row.experience[i].type = 7
                    }
                }
                axios.get('/pc/classes/allName/' + row.id + '/' + schoolId).then(function (res) {
                    const newEntries = [...row.month, ...row.dailyRate, ...row.classHour, ...row.quarterlyHarvest, ...row.forwardHarvest, ...row.lessonPackage, ...row.experience];

                    Vue.set(row, 'customRates', newEntries);
                    const initialRate = newEntries.length > 0 ? newEntries[0] : null;
                    this.selectedCourses.push({
                        name: row.name,
                        select: newEntries,
                        classList: res.data,
                        selectedRate: initialRate.id,
                        number: initialRate.number,
                        price: initialRate.price,
                        number2: '',
                        start_time: this.getCurrentDate(),
                        end_time: this.calculateOneMonthLater(),
                        classesId: '',
                        courseId: row.id,
                    });
                    console.log(this.selectedCourses, 'selectedCourses');
                    this.dialogTableVisible = false;
                }.bind(this));

            },
            //计算时间范围内除去星期六星期日的天数
            datejisuan(startDate, endDate) {
                let start = new Date(startDate);
                let end = new Date(endDate);
                let count = 0;
                // 循环遍历日期范围
                while (start <= end) {
                    // 获取当前日期是星期几 (0: Sunday, 1: Monday, ..., 6: Saturday)
                    let dayOfWeek = start.getDay();
                    // 如果是工作日 (1-5 代表周一到周五)
                    if (dayOfWeek >= 1 && dayOfWeek <= 5) {
                        count++;
                    }
                    // 将日期增加一天
                    start.setDate(start.getDate() + 1);
                }

                return count;
            },
            shuju(item) {
                var arr = []
                var obj = {}
                for (let i = 0; i < item.length; i++) {
                    for (let j = 0; j < item[i].select.length; j++) {
                        if (item[i].selectedRate == item[i].select[j].id) {
                            obj.courseName = item[i].select[j].name
                        }
                    }
                    for (let j = 0; j < item[i].classList.length; j++) {
                        if (item[i].classesId == item[i].classList[j].id) {
                            obj.className = item[i].classList[j].name
                        }
                    }
                    obj.end_time = item[i].end_time
                    obj.start_time = item[i].start_time
                    obj.number = item[i].number
                    obj.courseId = item[i].courseId
                    arr.push(obj)
                    obj = {}
                }
                return arr;
            },
            shuju2(item) {
                var arr = []
                var obj = {}
                // for (let i = 0; i < item.length; i++) {
                //     for (let j = 0; j < item[i].select.length; j++) {
                //         if (item[i].selectedRate == item[i].select[j].id) {
                //             obj.type = item[i].select[j].type
                //         }
                //     }
                for (let i = 0; i < item.length; i++) {
                    const selectedCourse = item[i].select.find(course => course.id === item[i].selectedRate);
                    // 如果选中的课程存在，添加课程名称
                    if (selectedCourse) {
                        obj.courseFeeStandard = selectedCourse.name + '(' + selectedCourse.price + '元/' + ['课时', '月', '天', '季', '期', '课包', '体验'][Number(selectedCourse.type) - 1] + ')'
                        obj.type = selectedCourse.type;
                    }
                    obj.classesId = item[i].classesId
                    obj.endTime = item[i].end_time
                    obj.startTime = item[i].start_time
                    obj.courseId = item[i].courseId
                    obj.coursePrice = (item[i].price * Number(item[i].number)) * 100
                    obj.quantity = item[i].number
                    if (item[i].number2) {
                        obj.amount = item[i].number2 * 100
                    } else {
                        obj.amount = (item[i].price * Number(item[i].number)) * 100
                    }

                    const oneDay = 24 * 60 * 60 * 1000; // 一天的毫秒数
                    const start = new Date(item[i].start_time);
                    const end = new Date(item[i].end_time);
                    if (obj.type == 2 || obj.type == 4 || obj.type == 5) {
                        const diffDays = this.datejisuan(start, end);
                        obj.number = diffDays;
                        obj.countNum = diffDays;
                    } else if (obj.type == 1 || obj.type == 3 || obj.type == 6 || obj.type == 7) {
                        obj.number = Number(item[i].number);
                        obj.countNum = obj.number;

                    }

                    arr.push(obj)
                    obj = {}
                }
                return arr;
            },
            //计算时间范围内除去星期六星期日的天数
            datejisuan(startDate, endDate) {
                let start = new Date(startDate);
                let end = new Date(endDate);
                let count = 0;
                // 循环遍历日期范围
                while (start <= end) {
                    // 获取当前日期是星期几 (0: Sunday, 1: Monday, ..., 6: Saturday)
                    let dayOfWeek = start.getDay();
                    // 如果是工作日 (1-5 代表周一到周五)
                    if (dayOfWeek >= 1 && dayOfWeek <= 5) {
                        count++;
                    }
                    // 将日期增加一天
                    start.setDate(start.getDate() + 1);
                }

                return count;
            },
            pay() {
                if (this.selectedCourses.length < 1) return alert('请选择课程')
                if (this.formLabelAlign.orderType == null) return alert('请选择类型')
                if (this.formLabelAlign.start_time == null) return alert('请选择收款日期')
                if (this.formLabelAlign.performance == null) return alert('请选择业绩归属人')
                var name = localStorage.getItem('staffUserName')
                var obj = {
                    studentId: this.studentId,
                    courseIdsStr: '',
                    handlingDate1: this.formLabelAlign.start_time,
                    finalPayment1: 0,
                    cent: this.totalAmount * 100,
                    // performance1: this.formLabelAlign.type,
                    classesId: '',
                    remark: this.formLabelAlign.remark,
                    performance1: this.formLabelAlign.performance,
                    orderType: this.formLabelAlign.orderType,
                    handleUser: name != 'null' ? name : sessionStorage.getItem('hxt-u'),
                    courseData: this.shuju(this.selectedCourses),
                    zongJia: this.totalAmount1 * 100,
                };
                var courseIdsStrArr = [];
                var classesIdArr = []
                for (let i = 0; i < this.selectedCourses.length; i++) {
                    courseIdsStrArr.push(this.selectedCourses[i].courseId)
                    if (this.selectedCourses[i].classesId) {
                        classesIdArr.push(this.selectedCourses[i].classesId)
                    }
                }
                obj.courseIdsStr = JSON.stringify(courseIdsStrArr)
                if (classesIdArr.length) obj.classesId = JSON.stringify(classesIdArr);

                axios.post('/pc/order/registration', obj).then(function (res) {
                    this.createQr(res.data.data)

                }.bind(this));
                this.dialogVisible = true

            },
            async pay1() {
                if (this.selectedCourses.length < 1) return alert('请选择课程')
                if (this.formLabelAlign.orderType == null) return alert('请选择类型')
                if (this.formLabelAlign.start_time == null) return alert('请选择收款日期')
                if (this.formLabelAlign.performance == null) return alert('请选择业绩归属人')
                // 循环遍历所有选中的课程
                for (let i = 0; i < this.selectedCourses.length; i++) {
                    const course = this.selectedCourses[i];
                    // 检查重复订单的接口请求
                    try {
                        const response = await axios.get('/pc/order/checkDuplicateOrder', {
                            params: {
                                studentId: this.studentId,
                                courseId: course.courseId,
                                startTime: course.start_time,
                                endTime: course.end_time
                            }
                        });

                        // 如果返回的数据 >= 1，表示存在重复订单，终止后继续操作
                        if (response.data >= 1) {
                            alert(`课程 ${course.name} 已存在相同订单，不能重复报名`);
                            return;  // 终止函数执行
                        }
                    } catch (error) {
                        console.error("检查重复订单时出错:", error);
                        alert("检查订单时出现错误，请稍后再试");
                        return; // 出现错误时终止后续操作
                    }
                }

                // 如果所有课程都通过了检查，则继续执行后续操作 
                var name = localStorage.getItem('staffUserName');
                if (!this.studentId) {
                    this.$message.error('请先选择关联学生')
                    this.$refs.studentPicker.focus() // 自动聚焦到学生选择组件
                    return
                }
                var obj = {
                    studentId: this.studentId,
                    courseIdsStr: '',
                    handlingDate1: this.formLabelAlign.start_time,
                    finalPayment1: 0,
                    cent: this.totalAmount * 100,
                    classesId: '',
                    remark: this.formLabelAlign.remark,
                    performance1: this.formLabelAlign.performance,
                    orderType: this.formLabelAlign.orderType,
                    handleUser: name !== 'null' ? name : sessionStorage.getItem('hxt-u'),
                    courseData: this.shuju(this.selectedCourses),
                    zongJia: this.totalAmount1 * 100,
                };

                var courseIdsStrArr = [];
                var classesIdArr = [];

                // 获取课程 ID 和班级 ID
                for (let i = 0; i < this.selectedCourses.length; i++) {
                    courseIdsStrArr.push(this.selectedCourses[i].courseId);
                    if (this.selectedCourses[i].classesId) {
                        classesIdArr.push(this.selectedCourses[i].classesId);
                    }
                }

                obj.courseIdsStr = JSON.stringify(courseIdsStrArr);
                if (classesIdArr.length) obj.classesId = JSON.stringify(classesIdArr);

                // 提交订单
                try {
                    const res = await axios.post('/pc/order/manualReconciliation', obj);
                    this.setkecheng(res.data.data);
                    this.dialogVisible = true;
                } catch (error) {
                    console.error("提交订单时出错:", error);
                    alert("提交订单时出现错误，请稍后再试");
                }
            },
            //归属人
            filName(id) {
                if (!id) return '空';
                var name = '';
                for (let i = 0; i < this.staffUsers.length; i++) {
                    if (this.staffUsers[i].id == id) {
                        name = this.staffUsers[i].name
                    }
                }
                return name;
            },
            //创建二维码
            createQr(data) {
                const qrcodeDiv = this.$refs.qrcode;
                const qrcodeText = data.payQr
                const qrcodeOptions = {
                    width: 200,
                    height: 200,
                };
                this.qrimg = new QRCode(qrcodeDiv, {
                    text: qrcodeText,
                    ...qrcodeOptions,
                });
                this.inquireOrder(data.orderId)
            },
            clearQRCodeInstance() {
                // 清除二维码实例
                if (this.qrimg) {
                    this.qrimg.clear();
                    this.$nextTick(() => {
                        let dom = this.$refs.qrcode
                        while (dom.firstChild) { dom.removeChild(dom.firstChild) }
                    });
                }
            },
            setkecheng(orderid) {
                var enroll = this.shuju2(this.selectedCourses)
                for (let i = 0; i < enroll.length; i++) {
                    enroll[i].orderId = orderid
                    enroll[i].studentId = this.studentId
                }
                for (let i = 0; i < enroll.length; i++) {
                    axios.post('/pc/order/studentCourse', enroll[i]).then(function (res) {
                        if (i == (enroll.length - 1)) {
                            if (res.data.code == 1) {

                                alert('学生成功报名该课程')
                                dialogVisible = false
                                // window.history.back();
                                window.location.href = 'school_orderXx.html'
                            }
                        }
                    }.bind(this));
                }
            },
            //查询订单状态
            inquireOrder(id) {
                var mysetInterval = setInterval(() => {
                    axios.postForm('/pc/order/order_paid', { orderId: id }).then(function (res) {
                        // console.log(res.data);
                        if (res.data.code == 1) {
                            this.setkecheng(id)
                            clearInterval(mysetInterval);
                            alert('支付成功')
                        }
                    }.bind(this));
                }, 2000);
                setTimeout(() => {
                    clearInterval(mysetInterval);
                }, 180000);
            },
            updateQuantity(row, newValue) {
                const newRate = row.select.find(item => item.id === newValue);
                row.number = (newRate && newRate.number);
                row.price = (newRate && newRate.price);

            },
            handleCurrentChange(val) {
                this.currentRow = val;
            },
            confirmDelete(index) {
                this.$confirm('确认删除吗?', '警告', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    this.deleteCourse(index);
                }).catch(() => {
                    /* this.$message({
                         type: 'info',
                         message: '已取消删除'
                     });*/
                });
            },
            deleteCourse(index) {
                this.selectedCourses.splice(index, 1);
                this.$message({
                    type: 'success',
                    message: '删除成功'
                });
            },
            submit() {
                this.clearQRCodeInstance()
                this.pay()

            },
            submit1() {
                this.pay1()
            },
            handleClose(done) {
                this.$confirm('确认关闭？')
                    .then(_ => {
                        done();
                    })
                    .catch(_ => { });
            },
            // 每页数
            sizeChangeHandle(val) {
                this.pageSize = val
                this.pageIndex = 1
                this.visibleopen()
            },
            // 当前页
            currentChangeHandle(val) {
                this.pageIndex = val
                this.visibleopen()
            }
        }

    }));
</script>

</html>